/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 123
 * Date: 2023-07-17
 * Time: 9:18
 */

public class BinarySearchTree {

    static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    public TreeNode root = null;

    public boolean search(int val) {
        TreeNode cur = root;
        while (cur != null) {
            if(cur.val < val) {
                cur = cur.right;
            }else if(cur.val > val) {
                cur = cur.left;
            }else {
                return true;
            }
        }
        return false;
    }

    public boolean insert(int val) {
        TreeNode node = new TreeNode(val) ;
        if(root == null) return false ;
       TreeNode parent = null ;
       TreeNode cur = this.root ;
       while(cur != null){
           if(val > cur.val){
               parent = cur ;
               cur = cur.right ;
           }else if(val < cur.val){
               parent = cur ;
               cur = cur.left ;
           }
           else
               return false;
       }
       if(val > parent.val){
           parent.right = node ;
       }
       if(val < parent.val){
           parent.left = node ;
       }


return true ;

    }
    public void remove(TreeNode root ){



    }


}

